<?php

namespace App\Http\Controllers;

use App\Library\Requests\Base\SerialNumberRequest;
use App\Library\Requests\ProductAlbum\ProductAlbumAddRequest;
use App\Library\Requests\ProductAlbum\ProductAlbumEditRequest;
use App\Library\Requests\ProductAlbum\ProductAlbumPageRequest;
use App\Library\Service\ShopProductAlbumService;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ShopProductAlbumController extends BaseController
{
    public function __construct(ShopProductAlbumService $service)
    {
        $this->service = $service;
    }

    /**
     * 新增
     * @param ProductAlbumAddRequest $request
     * @return JsonResponse
     *
     */
    public function add(ProductAlbumAddRequest $request): JsonResponse
    {
        return $this->service->add($request);
    }

    /**
     * delete
     * @param SerialNumberRequest $request
     * @return JsonResponse
     *
     */
    public function delete(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->delete($request);
    }

    /**
     * edit
     * @param ProductAlbumEditRequest $request
     * @return JsonResponse
     *
     */
    public function edit(ProductAlbumEditRequest $request): JsonResponse
    {
        return $this->service->edit($request);
    }

    /**
     * paging
     * @param ProductAlbumPageRequest $request
     * @return JsonResponse
     *
     */
    public function paging(ProductAlbumPageRequest $request): JsonResponse
    {
        return $this->service->paging($request);
    }

    /**
     * detail
     * @param SerialNumberRequest $request
     * @return JsonResponse
     *
     */
    public function detail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->detail($request);
    }

    /**
     *
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function transShareStatus(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->transShareStatus($request);
    }

    /**
     *
     * @param Request $request
     * @return Application|Factory|View|\Illuminate\Foundation\Application
     *
     */
    public function productAlbumDisplay(Request $request)
    {
        if (is_null($request->segment(2)) || strlen($request->segment(2)) !== 20) return view('error', ['message' => '数据不存在']);
        $model = $this->service->productAlbumDisplay($request->segment(2));
        if (!is_bool($model)) return view('product.product_album', ['info' => $model]);
        else return view('error', ['message' => '数据不存在']);
    }
}
